package com.hsy.swu.spider

import android.content.Context
import android.content.Intent
import com.hsy.swu.clouddb.MyUser
import com.hsy.swu.hsyutils.MActivityUtil
import com.hsy.swueasspider.utils.SwuEasCookieUtils

object SwuSpiderHelper {
    fun startSwuSpiderService(
        context: Context,
        account: String = MyUser.currentUser.account,
        password: String = MyUser.currentUser.password,
        cookie: String = ""
    ) {
        if (cookie.isNotEmpty()) {
            context.startService(
                Intent(context, SwuSpiderService::class.java)
                    .putExtra("account", account)
                    .putExtra("password", password)
                    .putExtra("Cookie", cookie)
            )
            return
        }
        SwuEasCookieUtils.ensureCookieUsable(
            context,
            account,
            password
        ) { mCookie ->
            MActivityUtil.showToast("开始更新数据")
            context.startService(
                Intent(context, SwuSpiderService::class.java)
                    .putExtra("account", account)
                    .putExtra("password", password)
                    .putExtra("Cookie", mCookie)
            )
        }
    }
}